package com.uit.project.bustrip;

import java.util.ArrayList;

import com.uit.project.bustrip.adapter.ListTripAdaper;
import com.uit.project.bustrip.bo.TripBOImpl;
import com.uit.project.bustrip.bointerface.TripBO;
import com.uit.project.bustrip.entity.Trip;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Home extends ListActivity {
	ArrayAdapter<Trip> adapter;
	ArrayList<Trip> items;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_home);
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
		.permitAll().build();
		StrictMode.setThreadPolicy(policy);
		TripBO tripBO = new TripBOImpl(getApplicationContext());
		items = (ArrayList<Trip>) tripBO.getAllTrip();
		adapter = new ListTripAdaper(this,items);
		setListAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

	/* (non-Javadoc)
	 * @see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)
	 */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		Trip trip = items.get(position);
		Intent i = new Intent(getApplicationContext(),ChoseSeat.class);
		i.putExtra("tripid", trip.id);
		startActivity(i);
	}

}
